home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 692 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.3 KB  |  71 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: tjb839@zacatecas.optimum.com (Tim Boemker)
  3. Newsgroups: comp.std.c++
  4. Subject: User-defined conversions
  5. Date: 12 Mar 1996 20:19:06 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <199603111535.AA12540@zacatecas.optimum.com>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Mon, 11 Mar 1996 10:35:09 -0500
  11. X-Authenticated: tjb839 on POP host zacatecas.optimum.com
  12. X-Mailed-From: InterNews 1.0.6@boemker.optimum.com
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMUZNMEy4NqrwXLNJAQEE0wH/Q4fhDH8jmB/1C3Fj6BBChKAm0u+xSNqn
  15.     HnbbVIsCT2pZeOEruxVWWv7tGhWetAIvu1xCDSxoaJNi6Bv1AVQgsA==
  16.     =4KPX
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. I'm trying to write a class template Like that extends the behavior of
  20. a (possibly built-in) type by defining conversions so that wherever a
  21. Like<T> appears it's implicitly converted to T& and wherever const
  22. Like<T> appears it's implicitly converted to const T&.
  23.  
  24.   template<class T> class Like<T> {
  25.   private:
  26.       T t;
  27.   public:
  28.       Like(T t_) : t(t_) {}
  29.       operator const T&() const { return t; }
  30.       operator T&() { return t; }
  31.       // ...
  32.   };
  33.  
  34. As I read the WP, the following code is ambiguous
  35.  
  36.   Like<T> x;
  37.   int y;
  38.   ...
  39.   if(x == y)
  40.     // do something
  41.  
  42. because the two candidate user-defined conversion sequences contain
  43. different user-defined conversion operators (although they differ only
  44. in their cv-qualifiers) and neither second standard conversion
  45. sequences is better.  This is not the way standard conversion sequences
  46. are compared.  In [over.ics.rank], the WP says
  47.  
  48.   Standard conversion sequence S1 is a better conversion sequence than
  49. standard
  50.   conversion sequence S2 if ... S1 and S2 differ only in their
  51. qualification
  52.   conversion and they yield types identical except for cv-qualifiers
  53. and S2 adds
  54.   all the qualifiers that S1 adds (and in the same places) and S2 adds
  55. more cv-
  56.   qualifiers than S1..."
  57.  
  58.  
  59. It seems to me that similar language ought to apply to user-defined
  60. conversions.
  61.  
  62. Tim Boemker
  63. Optimum Group
  64. ---
  65. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  66.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  67.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  68.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  69.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  70. ]
  71.